﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace BigPang.Server.Net
{
    public class Server<T>
    {
        static ServiceHost host;

        public static void Start(Type type, string name)
        {
            host = new ServiceHost(type);
            NetTcpBinding binding = new NetTcpBinding();
            //binding.ReceiveTimeout = TimeSpan.MaxValue;
            //binding.SendTimeout = TimeSpan.MaxValue;
            //binding.CloseTimeout = TimeSpan.MaxValue;
            binding.ReliableSession.Enabled = true;
            //binding.ReliableSession.InactivityTimeout = new TimeSpan(0, 5, 0);
            binding.ReliableSession.Ordered = true;
            binding.Security.Mode = SecurityMode.None;

            host.AddServiceEndpoint(typeof(T), binding, "net.tcp://0.0.0.0:8000/" + name);
            host.Open();
        }

        public static void Stop()
        {
            host.Close();
        }
    }
}
